﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

using FRL.DebtChased.ChaseWorkspace;
using FRL.DebtChased.Silverlight.Library;
using FRL.DebtChased.Silverlight.Library.RichContentService;

namespace FRL.DebtChased.ChildWindows
{

	/// <summary>
	/// Declaration of CallDebtorResultsWnd class
	/// Window for logging the results of a call to the debtor
	/// </summary>
	public partial class CallDebtorResultsWnd : ChildWindow
	{

		/////////////////////////////////////////////////////////////
		// Construction

		public CallDebtorResultsWnd( List<ContactPointTransport> debtorContactPoints)
		{

			// Load xaml resources
			InitializeComponent();

			// Load the point grid
			for (int i1 = 0; i1 < debtorContactPoints.Count; i1++)
			{

				// Add row to grid
				RowDefinition row  = new RowDefinition();
				row.Height = new GridLength(0, GridUnitType.Auto);
				gridPoints.RowDefinitions.Add(row);

				// Get new row index
				int iRowIndex = gridPoints.RowDefinitions.Count - 1;

				// Populate row with controls
				TextRectangleCtrl trPoint = new TextRectangleCtrl();
				gridPoints.Children.Add(trPoint);
				Grid.SetRow(trPoint,iRowIndex);
				trPoint.Text = debtorContactPoints[i1].Address;
				trPoint.Style = this.Resources["CellDataStyle"] as Style;

				// Add checkboxes
				for( int iCol=1; iCol<=6; iCol++ )
				{

					// Add rectangle
					Rectangle rect = new Rectangle();
					gridPoints.Children.Add(rect);
					rect.Style = this.Resources["RectangleStyle"] as Style;
					Grid.SetColumn(rect,iCol);
					Grid.SetRow(rect,iRowIndex);

					// Add checkbox
					CheckBox chk = new CheckBox();
					gridPoints.Children.Add(chk);
					chk.Style = this.Resources["CellCheckBoxStyle"] as Style;
					Grid.SetColumn(chk, iCol);
					Grid.SetRow(chk, iRowIndex);

				} // for-loop

			}

			// Update the run
			runSummary.Text = string.Format("{0} called debtor, {1}",
				CachedData.Singleton.UserSessionTransport.UserDescription, 
				DateTime.Now.ToString()
			);

		}

		/////////////////////////////////////////////////////////////
		// Event handlers

		private void OKButton_Click(object sender, RoutedEventArgs e)
		{

			// Option for user
			if (!MessageBoxes.PopupOption("Save changes to account?"))
				return;

			// Message for user
			MessageBoxes.PopupDevMessage();

		}

		private void CancelButton_Click(object sender, RoutedEventArgs e)
		{

			// Close dialog
			this.DialogResult = false;

		}

	}

}

